<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>基础数据-库位管理</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
</head>
<body>
	<div id="mainContent">
		<div id="mainContent_content">
			<div class="page_header"><a>库位管理</a></div>
			<div class="search">
			<form method="post" action="<%=basePath %>inventorylocation/listInventoryLocation.do" class="form">
			<p>
				<input type="hidden" name="currentPage" value="1"/>
				<input type="hidden" name="inventorylocationid" value="0"/>
				<label>仓库</label>
				<select name="warehouseManagementID" class="form-control select" onchange="$(this).parent().parent().submit();">
					<option value="">全部</option>
					<c:forEach items="${warehoseList }" var="warehouse">
						<option value="${warehouse.warehousemanagementid }" <c:if test="${warehouse.warehousemanagementid==inventoryLocationPage.warehouseManagementID }">selected</c:if>>${warehouse.warehousename }</option>
					</c:forEach>
				</select>
				
				<!-- <input type="submit" value="搜索" class="btn btn1"></input>	 -->
				<c:if test="${isAdd }">
					<input type="button" value="同级新增" onclick="addInventoryLocation(${inventoryLocationPage.inventorylocationid });" class="btn btn1"></input>				
					<c:if test="${inventoryLocationPage.secondid <3}">
						<input type="button" value="下级新增" onclick="toAddInventoryLocation();" class="btn btn1"></input>
					</c:if>
				</c:if>
				<input type="button" value="编辑" onclick="toEditInventoryLocation();" class="btn btn2"></input>
				<c:if test="${isDelete }">
					<input type="button" value="删除" onclick="toDeleteInventoryLocation();" class="btn btn_danger"></input>
				</c:if>
				<c:if test="${inventoryLocationPage.secondid <3}">
					<input type="button" value="查看下级" onclick="showChild();" class="btn btn1"></input>
				</c:if>
				<c:if test="${inventoryLocationPage.secondid >1  }">
					<input type="button" value="返回上一级" class="btn btn2" onclick="location.href='<%=basePath %>inventorylocation/listInventoryLocation.do?currentPage=1&inventorylocationid=${inventoryLocationPage.firstid}'"></input>
				</c:if>
			</p>
			</form>
			</div>
			<div class="tableBox box">
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th></th>
							<th style="width:300px;">操作</th>
							<th>库位编码</th>
							<th>库位名称</th>
							<th>所属仓库</th>
							<th>创建时间</th>
							<th>创建人</th>
							<th>备注</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${inventoryLocationList}" var="inventorylocation" varStatus="i">
							<tr onclick="selectRow(this);">
								<td><label class="radio"><input type="radio" name="operateInventoryLocation" value="${inventorylocation.inventorylocationid }"><span class="radio_icon"></span></label></td>
								<td>
									<c:if test="${isAdd }">
										<a class="btn btn-xs btn1" onclick="addInventoryLocation(${inventorylocation.inventorylocationid });" >下级新增</a>
									</c:if>
									<a class="btn btn-xs btn2" href="<%=basePath %>inventorylocation/listInventoryLocation.do?currentPage=1&inventorylocationid=${inventorylocation.inventorylocationid }">查看下级</a>
									<a class="btn btn-xs btn1" onclick="editInventoryLocation(${inventorylocation.inventorylocationid });">编辑</a>
									<c:if test="${isDelete }">
										<a class="btn btn-xs btn_danger" onclick="confirmDeleteInventoryLocation(${inventorylocation.inventorylocationid });" >删除</a>
									</c:if>
								</td>
								<td>${inventorylocation.inventorylocationcode }</td>
								<td>${inventorylocation.inventorylocationname }</td>
								<td>${inventorylocation.warehouseName }</td>
								<td><fmt:formatDate value="${inventorylocation.createtime }" type="both" /></td>
								<td>${inventorylocation.createpersonname }</td>
								<td>${inventorylocation.description }</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<jsp:include page="/jsp/basic/page.jsp"></jsp:include>
		</div>
		<jsp:include page="/jsp/basicData/inventoryLocation/addInventoryLocation.jsp"></jsp:include>
		<jsp:include page="/jsp/basicData/inventoryLocation/editInventoryLocation.jsp"></jsp:include>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">
		function selectRow(obj){
			$(obj).find('input:radio[name="operateInventoryLocation"]')[0].checked=true;
		}
		
		function showChild(){
			var radio=$('input:radio[name="operateInventoryLocation"]:checked');
			if(!radio.val()){
				Prompt.alert("提示","请先选中需要查看下级的库位！");
				return;
			}
			location.href="<%=basePath %>inventorylocation/listInventoryLocation.do?currentPage=1&inventorylocationid="+radio.val();
		}
		
		function toEditInventoryLocation(){
			var radio=$('input:radio[name="operateInventoryLocation"]:checked');
			if(!radio.val()){
				Prompt.alert("提示","请先选中需要编辑的库位！");
				return;
			}
			editInventoryLocation(radio.val());
		}
		
		function toAddInventoryLocation(){
			var radio=$('input:radio[name="operateInventoryLocation"]:checked');
			if(!radio.val()){
				Prompt.alert("提示","请先选中需要新增下级的库位！");
				return;
			}
			addInventoryLocation(radio.val());
		}
		
		function toDeleteInventoryLocation(){
			var radio=$('input:radio[name="operateInventoryLocation"]:checked');
			if(!radio.val()){
				Prompt.alert("删除提示","请先选中需要删除的库位！");
				return;
			}
			confirmDeleteInventoryLocation(radio.val());
		}
			
		function confirmDeleteInventoryLocation(id){
			var delFunc=function(){
				$.ajax({
					url:"<%=basePath %>inventorylocation/delete.do",
					type:"post",
					async : false,
					dataType:"json",
					data : "inventorylocationid="+id,
					success:function(data){
						if(data.result=="success"){
							Prompt.alert("删除提示","库位已删除！",Prompt.refresh);
						}
					},
					error :function(){
						Prompt.alert("删除提示","服务器无响应，请刷新页面后重试！");
					}
				});
			}
			Prompt.confirm("提示","确认要删除该库位吗?删除后无法恢复",delFunc);
		}
	</script>
</body>
</html>